﻿/*
 *  Copyright 2009 Duck Pond, Inc.
 *  http://www.duckpondinc.com/
 *  
 *  This file is part of Server Watch & Alert.
 *
 *  Server Watch & Alert is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Server Watch & Alert is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Server Watch & Alert.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * */

using System;
using System.Xml.Serialization;

namespace DuckPond.ServerWatchAlert.Core.TestActions
{
    /// <summary>
    /// Represents an action, either for testing a server
    /// or responding to events or other commands.
    /// </summary>
    public abstract class TestAction
    {
        /////////////////////
        // FIELDS
        /////////////
        protected TimeSpan _MaxAlertRate;
        protected TimeSpan _Interval;


        /////////////////////
        // PROPERTIES
        /////////////
        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlAttribute("max-alert-rate")]
        public string MaxAlertRateRaw
        {
            get
            {
                return Convert.ToString(_MaxAlertRate);
            }
            set
            {
                _MaxAlertRate = TimeSpan.Parse(value);
            }
        }

        public TimeSpan MaxAlertRate
        {
            get
            {
                return _MaxAlertRate;
            }
            set
            {
                _MaxAlertRate = value;
            }
        }

        [XmlAttribute("interval")]
        public string IntervalRaw
        {
            get
            {
                return Convert.ToString(_Interval);
            }
            set
            {
                _Interval = TimeSpan.Parse(value);
            }
        }

        public TimeSpan Interval
        {
            get
            {
                return _Interval;
            }
            set
            {
                _Interval = value;
            }
        }


        /////////////////////
        // METHODS
        /////////////
        /// <summary>
        /// Returns true if suceeded. False if failed.
        /// </summary>
        /// <returns></returns>
        public abstract TestResult PerformAction();
    }
}
